package com.shitou.shitouproduct.controller;

import java.util.Arrays;
import java.util.Map;

import com.shitou.shitoucommons.annotation.CheckUserLogin;
import com.shitou.shitouproduct.entity.BrandEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import com.shitou.shitouproduct.service.BrandService;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.RespBean;



/**
 * 品牌
 *
 * @author 石头人
 * @email 3076767823@qq.com
 * @date 2023-03-04 18:03:45
 */
@RestController
@RequestMapping("shitouproduct/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return RespBean.success().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public RespBean info(@PathVariable("brandId") Long brandId){
        BrandEntity brand = brandService.getById(brandId);

        return RespBean.success().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody BrandEntity brand){
        brandService.save(brand);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody BrandEntity brand){
        brandService.updateById(brand);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] brandIds){
        brandService.removeByIds(Arrays.asList(brandIds));

        return RespBean.success();
    }


    /**
     * 通过分类id获取品牌,右他们的关联表
     * @param categoryId
     * @return
     */
    @ApiOperation(value = "通过分类id获取品牌,通过他们的关联表，需要登陆校验")
    @CheckUserLogin
    @PostMapping("/categoryBrand")
    public RespBean getBrandByCategoryId(int categoryId){
        return brandService.getBrandByCategoryId(categoryId);
    }



    @RequestMapping("/update/status")
    public RespBean updateStatus(@RequestBody BrandEntity brand){
        return brandService.updateStatus(brand);
    }
}
